package com.CST.controller.zx;

import com.CST.common.api.ResultObject;
import com.CST.dto.zx.AuditDTO;
import com.CST.dto.zx.ProSelDTO;
import com.CST.service.zx.IZX_AuditService;
import com.CST.service.zx.IZX_ProjectInfoService;
import com.CST.service.zx.IZxFinancialService;
import com.CST.util.PageHelperTool;
import com.CST.vo.zx.ZxAuditVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "审核管理")
@RestController
public class ZxAuditController {

    @Autowired
    IZX_AuditService zxAuditService;

    @Autowired
    IZX_ProjectInfoService zxProjectInfoService;

    @Autowired
    IZxFinancialService zxFinancialService;

    @PostMapping("/getList")
    @ApiOperation(value = "审核列表")
    public ResultObject<PageInfo<ZxAuditVO>> getList(@RequestBody ProSelDTO proSelDTO) {
        List<ZxAuditVO> result = zxAuditService.getList(proSelDTO);
        PageInfo<ZxAuditVO> pageResult = PageHelperTool.excutePageInfo(result, proSelDTO.getPageNum(), proSelDTO.getPageSize());
        return ResultObject.success(pageResult);
    }

    @PostMapping("/auditOperation")
    @ApiOperation(value = "审核操作")
    public ResultObject auditOperation(@RequestBody AuditDTO auditVO) {
        Integer result = zxAuditService.audit(auditVO);
        if (result > 0) {
            if (auditVO.getStatus() == 1) {
                //通过:做删除项目操作
                zxFinancialService.deleteFinancialProject(auditVO.getFinancialCode());
                zxProjectInfoService.deleteProject(auditVO.getFinancialCode());
            }
        }
        return ResultObject.success("操作成功");
    }
}
